/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package org.amarena2d.examples.android;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import com.android1.amarena2d.android.AmarenaAndroidEngine;
import com.android1.amarena2d.engine.Config;
import com.android1.amarena2d.nodes.Scene;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.android.surfaceview.FixedResolutionStrategy;
import org.amarena2d.examples.Example;

public class SimpleScenePlayer extends AmarenaAndroidEngine {


    String sceneClass;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        sceneClass = (String) getIntent().getExtras().get("scene");

        if (sceneClass != null) {

            try {
                Class<Scene> clazz = (Class<Scene>) Class.forName(sceneClass);

                Example example = clazz.getAnnotation(Example.class);
                Config config = new Config(example.width(), example.height());
                config.setBaseAssetsPath("org/amarena2d/examples/scenes/assets/");
                config.setDefaultFileType(Files.FileType.Classpath);
                loadEngine(config, new FixedResolutionStrategy(config.getCameraWith(), config.getCameraHeight()));

            } catch (ClassNotFoundException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }

    }

    @Override
    public void surfaceCreated() {

        try {
            Class clazz = Class.forName(sceneClass);
            Scene scene = (Scene) clazz.newInstance();
            engine().getDirector().runScene(scene);
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }


    }
}

